package com.lession.controller;

import com.lession.Dto.LoginVerificateReqDto;
import com.lession.Dto.LoginVerificateRspDto;
import com.lession.common.LessionException;
import com.lession.common.Ret;
import com.lession.common.RetEnum;
import com.lession.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/login")
public class LoginController {
	@Autowired
	private LoginService loginService;
	
	// 登录验证
	@RequestMapping(value = "verificate", method = RequestMethod.POST)
	public Ret<LoginVerificateRspDto> verificate(@RequestBody LoginVerificateReqDto param, HttpServletRequest request) {
		try {
			// 调用loginService的verificate方法进行登录验证
			return Ret.ok().data(loginService.verificate(param)).build();
		} catch (LessionException e) {
			// 捕获LessionException异常，并返回相应的错误码和错误消息
			return Ret.error(e.getCode()).msg(e.getMessage()).build();
		} catch (Exception e) {
			// 捕获其他类型的异常，并返回接口调用失败的错误码
			return Ret.error(RetEnum.INTERFACE_CALL_FAIL_ERROR.getCode()).build();
		}
	}
}
